//
//  GNRModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit
enum GNRType: Int {
    case J = 0
    case kgm
    case psh
    case hph
    case kwh
    case du
    case cal
    case kcal
    case btu
    case ftlb
    case kJ
}


class GNRModel: NSObject {
    let types = ["焦耳","公斤·米","米制马力·时","英制马力·时","千瓦·时","度","卡","千卡","英热单位","英尺·磅","千焦"]
    let signs = ["J","kg·m","ps·h","hp·h","kW·h","kW·h","cal","kcal","btu","ft·lb","kJ"]
    
    
    func kmTall(n: Double, type: GNRType, reverse: Bool = false) -> Double {
        var km3 = n
        switch type {
        case .J:
            break
        case .kgm:
            km3 = reverse ? n / 0.102: n * 0.102
            break
        case .psh:
            km3 = reverse ? n / 3.7767e-7: n * 3.7767e-7
            break
        case .hph:
            km3 = reverse ? n / 3.7251e-7: n * 3.7251e-7
            break
        case .kwh:
            km3 = reverse ? n / 2.7778e-7: n * 2.7778e-7
            break
        case .du:
            km3 = reverse ? n / 2.7778e-7: n * 2.7778e-7
            break
        case .cal:
            km3 = reverse ? n / 0.2389: n * 0.2389
            break
        case .kcal:
            km3 = reverse ? n / 0.0002389: n * 0.0002389
            break
        case .btu:
            km3 = reverse ? n / 0.0009478: n * 0.0009478
            break
        case .ftlb:
            km3 = reverse ? n / 0.7376: n * 0.7376
            break
        case .kJ:
            km3 = reverse ? n / 0.001: n * 0.001
            break
        }
        return km3
    }

    
    func allChange(d: Double, type: GNRType) -> [String] {
        let km = kmTall(n: d, type: type, reverse: true)
        
        
        
        return ["\(kmTall(n: km, type: .J))\(signs[0])","\(kmTall(n: km, type: .kgm))\(signs[1])",
                "\(kmTall(n: km, type: .psh))\(signs[2])","\(kmTall(n: km, type: .hph))\(signs[3])",
                "\(kmTall(n: km, type: .kwh))\(signs[4])","\(kmTall(n: km, type: .du))\(signs[5])",
                "\(kmTall(n: km, type: .cal))\(signs[6])","\(kmTall(n: km, type: .kcal))\(signs[7])","\(kmTall(n: km, type: .btu))\(signs[8])","\(kmTall(n: km, type: .ftlb))\(signs[9])","\(kmTall(n: km, type: .kJ))\(signs[10])"]

    }

}
